package model;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Album
 * 
 * @author orlin
 */
public class Album {

	public static final String AND = ",";

	private String released;
	private String item;
	private String catalog;
	private String format;
	private String title;

	private Set<Artist> artists = new LinkedHashSet<Artist>();
	private Set<Track> tracks = new LinkedHashSet<Track>();
	private Set<Credit> credits = new LinkedHashSet<Credit>();

	public Album() {
	}

	public Album(String released, String item, String catalog, String format, String title, Collection<Artist> artists, Collection<Track> tracks, Collection<Credit> credits) {
		super();
		this.released = released;
		this.item = item;
		this.catalog = catalog;
		this.format = format;
		this.title = title;
		setArtists(artists);
		setTracks(tracks);
		setCredits(credits);
	}

	public String getReleased() {
		return released;
	}
	public void setReleased(String released) {
		this.released = released;
	}
	public String getItem() {
		return item;
	}
	public void setItem(String item) {
		this.item = item;
	}
	public String getCatalog() {
		return catalog;
	}
	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}
	public String getFormat() {
		return format;
	}
	public void setFormat(String format) {
		this.format = format;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getArtist() {
		StringBuffer result = new StringBuffer();
		for (Artist artist: artists) {
			if (result.length() != 0) {
				result.append(AND);
				result.append(" ");
			}
			result.append(artist.getName());
		}
		return result.toString();
	}
	public Collection<Artist> getArtists() {
		return artists;
	}
	public void setArtists(Collection<Artist> artists) {
		this.artists.clear();
		if (artists != null) {
			this.artists.addAll(artists);
		}
	}
	public void addArtist(Artist artist) {
		artists.add(artist);
	}
	public Collection<Track> getTracks() {
		return tracks;
	}
	public void setTracks(Collection<Track> tracks) {
		this.tracks.clear();
		if (tracks != null) {
			this.tracks.addAll(tracks);
		}
	}
	public void addTrack(Track track) {
		tracks.add(track);
	}
	public Collection<Credit> getCredits() {
		return credits;
	}
	public void setCredits(Collection<Credit> credits) {
		this.credits.clear();
		if (credits != null) {
			this.credits.addAll(credits);
		}
	}
	public void addCredit(Credit credit) {
		credits.add(credit);
	}

	@Override
	public String toString() {
		StringBuffer line = new StringBuffer();
		line.append("AlbumDto [released:");
		line.append(released);
		line.append(", item:");
		line.append(item);
		line.append(", catalog:");
		line.append(catalog);
		line.append(", format:");
		line.append(format);
		line.append(", title:");
		line.append(title);
		line.append(", artists:");
		line.append(artists);
		line.append(", tracks:");
		line.append(tracks);
		line.append(", credits:");
		line.append(credits);
		line.append("]");
		return line.toString();
	}
}
